call vimtex#init()
" call vimtex#options#init()
" call vimtex#syntax#core#init_options()
" call vimtex#syntax#core#init_rules()
" call vimtex#syntax#core#init_highlights()
" call vimtex#text_obj#init_buffer()
" call vimtex#text_obj#targets#init()
" call vimtex#state#init_buffer()
" call vimtex#cmd#init_buffer()
" call vimtex#motion#init_buffer()
" call vimtex#delim#init_buffer()
" call vimtex#env#init_buffer()

function! s:map(ftype, mode, lhs, rhs, ...) abort
  silent execute a:mode . 'map <silent><buffer><nowait>' a:lhs a:rhs
endfunction

" call s:map(0, 'n', 'ds$', '<plug>(vimtex-env-delete-math)')
" call s:map(0, 'n', 'cs$', '<plug>(vimtex-env-change-math)')
call s:map(0, 'n', 'dsm', '<plug>(vimtex-env-delete-math)')
call s:map(0, 'n', 'csm', '<plug>(vimtex-env-change-math)')
call s:map(0, 'n', 'dse', '<plug>(vimtex-env-delete)')
call s:map(0, 'n', 'cse', '<plug>(vimtex-env-change)')
call s:map(0, 'n', 'tse', '<plug>(vimtex-env-toggle-star)')
" call s:map(0, 'n', 'ts$', '<plug>(vimtex-env-toggle-math)')
call s:map(0, 'n', 'tsm', '<plug>(vimtex-env-toggle-math)')
call s:map(0, 'n', 'dsc',  '<plug>(vimtex-cmd-delete)')
call s:map(0, 'n', 'csc',  '<plug>(vimtex-cmd-change)')
call s:map(0, 'n', 'tsc',  '<plug>(vimtex-cmd-toggle-star)')
call s:map(0, 'n', 'tf',  '<plug>(vimtex-cmd-toggle-frac)')
call s:map(0, 'x', 'tf',  '<plug>(vimtex-cmd-toggle-frac)')
" call s:map(0, 'i', '<F7>', '<plug>(vimtex-cmd-create)')
" call s:map(0, 'n', '<F7>', '<plug>(vimtex-cmd-create)')
" call s:map(0, 'x', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'i', '<C-A-c>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'n', '<leader>nc', '<plug>(vimtex-cmd-create)')
call s:map(0, 'x', '<leader>nc', '<plug>(vimtex-cmd-create)')
call s:map(0, 'n', 'dsd', '<plug>(vimtex-delim-delete)')
call s:map(0, 'n', 'csd', '<plug>(vimtex-delim-change-math)')
call s:map(0, 'i', '<C-d>', '<esc><plug>(vimtex-delim-toggle-modifier)a')
call s:map(0, 'n', 'tsd', '<plug>(vimtex-delim-toggle-modifier)')
call s:map(0, 'x', 'tsd', '<plug>(vimtex-delim-toggle-modifier)')
call s:map(0, 'n', 'tsD', '<plug>(vimtex-delim-toggle-modifier-reverse)')
call s:map(0, 'x', 'tsD', '<plug>(vimtex-delim-toggle-modifier-reverse)')
" call s:map(0, 'i', ']]',  '<plug>(vimtex-delim-close)')
call s:map(0, 'i', '<C-}>',  '<plug>(vimtex-delim-close)<BS>')
" call s:map(0, 'n', '<F8>', '<plug>(vimtex-delim-add-modifiers)')
call s:map(0, 'n', '%', '<plug>(vimtex-%)', 1)
call s:map(0, 'x', '%', '<plug>(vimtex-%)', 1)
call s:map(0, 'o', '%', '<plug>(vimtex-%)', 1)
" call s:map(1, 'n', ']]', '<plug>(vimtex-]])')
" call s:map(1, 'n', '][', '<plug>(vimtex-][)')
" call s:map(1, 'n', '[]', '<plug>(vimtex-[])')
" call s:map(1, 'n', '[[', '<plug>(vimtex-[[)')
" call s:map(1, 'x', ']]', '<plug>(vimtex-]])')
" call s:map(1, 'x', '][', '<plug>(vimtex-][)')
" call s:map(1, 'x', '[]', '<plug>(vimtex-[])')
" call s:map(1, 'x', '[[', '<plug>(vimtex-[[)')
" call s:map(1, 'o', ']]', '<plug>(vimtex-]])')
" call s:map(1, 'o', '][', '<plug>(vimtex-][)')
" call s:map(1, 'o', '[]', '<plug>(vimtex-[])')
" call s:map(1, 'o', '[[', '<plug>(vimtex-[[)')
call s:map(1, 'n', ']M', '<plug>(vimtex-]M)')
call s:map(1, 'n', ']m', '<plug>(vimtex-]m)')
call s:map(1, 'n', '[M', '<plug>(vimtex-[M)')
call s:map(1, 'n', '[m', '<plug>(vimtex-[m)')
call s:map(1, 'x', ']M', '<plug>(vimtex-]M)')
call s:map(1, 'x', ']m', '<plug>(vimtex-]m)')
call s:map(1, 'x', '[M', '<plug>(vimtex-[M)')
call s:map(1, 'x', '[m', '<plug>(vimtex-[m)')
call s:map(1, 'o', ']M', '<plug>(vimtex-]M)')
call s:map(1, 'o', ']m', '<plug>(vimtex-]m)')
call s:map(1, 'o', '[M', '<plug>(vimtex-[M)')
call s:map(1, 'o', '[m', '<plug>(vimtex-[m)')
call s:map(1, 'n', ']N', '<plug>(vimtex-]N)')
call s:map(1, 'n', ']n', '<plug>(vimtex-]n)')
call s:map(1, 'n', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'n', '[n', '<plug>(vimtex-[n)')
call s:map(1, 'x', ']N', '<plug>(vimtex-]N)')
call s:map(1, 'x', ']n', '<plug>(vimtex-]n)')
call s:map(1, 'x', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'x', '[n', '<plug>(vimtex-[n)')
call s:map(1, 'o', ']N', '<plug>(vimtex-]N)')
call s:map(1, 'o', ']n', '<plug>(vimtex-]n)')
call s:map(1, 'o', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'o', '[n', '<plug>(vimtex-[n)')
" call s:map(1, 'n', ']R', '<plug>(vimtex-]R)')
" call s:map(1, 'n', ']r', '<plug>(vimtex-]r)')
" call s:map(1, 'n', '[R', '<plug>(vimtex-[R)')
" call s:map(1, 'n', '[r', '<plug>(vimtex-[r)')
" call s:map(1, 'x', ']R', '<plug>(vimtex-]R)')
" call s:map(1, 'x', ']r', '<plug>(vimtex-]r)')
" call s:map(1, 'x', '[R', '<plug>(vimtex-[R)')
" call s:map(1, 'x', '[r', '<plug>(vimtex-[r)')
" call s:map(1, 'o', ']R', '<plug>(vimtex-]R)')
" call s:map(1, 'o', ']r', '<plug>(vimtex-]r)')
" call s:map(1, 'o', '[R', '<plug>(vimtex-[R)')
" call s:map(1, 'o', '[r', '<plug>(vimtex-[r)')
" call s:map(1, 'n', ']/', '<plug>(vimtex-]/)')
" call s:map(1, 'n', ']*', '<plug>(vimtex-]*)')
" call s:map(1, 'n', '[/', '<plug>(vimtex-[/)')
" call s:map(1, 'n', '[*', '<plug>(vimtex-[*)')
" call s:map(1, 'x', ']/', '<plug>(vimtex-]/)')
" call s:map(1, 'x', ']*', '<plug>(vimtex-]*)')
" call s:map(1, 'x', '[/', '<plug>(vimtex-[/)')
" call s:map(1, 'x', '[*', '<plug>(vimtex-[*)')
" call s:map(1, 'o', ']/', '<plug>(vimtex-]/)')
" call s:map(1, 'o', ']*', '<plug>(vimtex-]*)')
" call s:map(1, 'o', '[/', '<plug>(vimtex-[/)')
" call s:map(1, 'o', '[*', '<plug>(vimtex-[*)')
call s:map(0, 'x', 'id', '<plug>(vimtex-id)')
call s:map(0, 'x', 'ad', '<plug>(vimtex-ad)')
call s:map(0, 'o', 'id', '<plug>(vimtex-id)')
call s:map(0, 'o', 'ad', '<plug>(vimtex-ad)')
" call s:map(0, 'x', 'i$', '<plug>(vimtex-i$)')
" call s:map(0, 'x', 'a$', '<plug>(vimtex-a$)')
" call s:map(0, 'o', 'i$', '<plug>(vimtex-i$)')
" call s:map(0, 'o', 'a$', '<plug>(vimtex-a$)')
call s:map(0, 'x', 'im', '<plug>(vimtex-i$)')
call s:map(0, 'x', 'am', '<plug>(vimtex-a$)')
call s:map(0, 'o', 'im', '<plug>(vimtex-i$)')
call s:map(0, 'o', 'am', '<plug>(vimtex-a$)')
call s:map(1, 'x', 'iP', '<plug>(vimtex-iP)')
call s:map(1, 'x', 'aP', '<plug>(vimtex-aP)')
call s:map(1, 'o', 'iP', '<plug>(vimtex-iP)')
call s:map(1, 'o', 'aP', '<plug>(vimtex-aP)')
call s:map(1, 'x', 'im', '<plug>(vimtex-im)')
call s:map(1, 'x', 'am', '<plug>(vimtex-am)')
call s:map(1, 'o', 'im', '<plug>(vimtex-im)')
call s:map(1, 'o', 'am', '<plug>(vimtex-am)')
call s:map(0, 'x', 'ic', '<plug>(vimtex-targets-i)c')
call s:map(0, 'x', 'ac', '<plug>(vimtex-targets-a)c')
call s:map(0, 'o', 'ic', '<plug>(vimtex-targets-i)c')
call s:map(0, 'o', 'ac', '<plug>(vimtex-targets-a)c')
call s:map(0, 'x', 'ie', '<plug>(vimtex-ie)')
call s:map(0, 'x', 'ae', '<plug>(vimtex-ae)')
call s:map(0, 'o', 'ie', '<plug>(vimtex-ie)')
call s:map(0, 'o', 'ae', '<plug>(vimtex-ae)')
call s:map(0, 'x', 'ic', '<plug>(vimtex-ic)')
call s:map(0, 'x', 'ac', '<plug>(vimtex-ac)')
call s:map(0, 'o', 'ic', '<plug>(vimtex-ic)')
call s:map(0, 'o', 'ac', '<plug>(vimtex-ac)')
